﻿Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Modules.GeminorumSoftwareContacts.Data
Imports DotNetNuke.Entities.Content

Public Class ContactController

    Public Shared Function GetContact(ContactID As Integer) As Contact
        Return CBO.FillObject(Of Contact)(DataProvider.Instance.GetContact(ContactID))
    End Function

    Public Shared Function GetContacts(ModuleID As Integer) As System.Collections.Generic.List(Of Contact)
        Return CBO.FillCollection(Of Contact)(DataProvider.Instance.GetContacts(ModuleID))
    End Function

    Public Shared Sub DeleteContact(ContactID As Integer)
        DataProvider.Instance.DeleteContact(ContactID)
    End Sub

    Public Shared Sub DeleteContacts(ModuleID As Integer)
        DataProvider.Instance.DeleteContacts(ModuleID)
    End Sub

    Public Shared Function SaveContact(Contact As Contact, TabID As Integer) As Integer
        If Contact.ID = 0 Then
            Dim cntTaxonomy As New ContactContent(New DotNetNukeContentItemController, New Terms(New DotNetNukeTermController), New DotNetNukeContentTypeController)
            Dim objContentItem As ContentItem = cntTaxonomy.CreateContentItem(Contact, TabID)
            Contact.ContentItemId = objContentItem.ContentItemId
            DataProvider.Instance.AddContact(Contact)
        Else
            DataProvider.Instance.UpdateContact(Contact)
        End If

        Return Contact.ID
    End Function
End Class